package com.yunshang.shoppingmall.common;

import com.yunshang.shoppingmall.entity.Config;

import java.io.UnsupportedEncodingException;

public class SMSAPI {

//    @Autowired
//    private ConfigService configService1;
//    private static ConfigService configService;
//
//    @PostConstruct
//    public void init() {configService=configService1;}

    //发送短信接口
    public static String SMSAPI(String phone,String template,String strContent,Config config) {
//       config = configService.selectByPrimaryKey(1);
        String data="?ac=send&uid="+config.getSmsAccount()+"&pwd="+config.getSmsPwd()+"&template="+template+"&mobile="+phone+"&content="+strContent;
        byte[] b= new byte[0];
        try {
            b = data.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        String res=HttpRequest.doPostRequest("http://api.sms.cn/sms/"+data,b);
//        String res="";
        return res;
    }

    //手机验证码-登录
    public static String SMSAPI_code(String phone,String codeValue,Config config) {

        String strContent = "{\"code\":\""+codeValue+"\"}";

        return SMSAPI(phone,"424051",strContent,config);
    }
    //切换编号验证码
    public static String SMSAPI_UserNo(String phone,String codeValue,Config config)
    {
        String strContent = "{\"code\":\""+codeValue+"\"}";
        return SMSAPI(phone,"478814",strContent,config);
    }
    //手机验证码-注册
    public static String SMSAPI_Reg_code(String phone,String codeValue,Config config)
    {
        String strContent = "{\"code\":\""+codeValue+"\"}";
        return SMSAPI(phone,"475374",strContent,config);
    }

    //手机验证码-找回密码验证码
    public static String SMSAPI_Pwd_code(String phone,String codeValue,Config config)
    {
        String strContent = "{\"code\":\""+codeValue+"\"}";
        return SMSAPI(phone,"475426",strContent,config);
    }

    //手机验证码-找回密码验证码
    public static String SMSAPI_Regin(String phone,String username,String password,Config config)
    {
        String strContent = "{\"username\":\""+username+"\",\"password\":\""+password+"\"}";
        return SMSAPI(phone,"509257",strContent,config);
    }
}
